package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.product.*;
import com.mes.cloud.api.dto.response.product.ProductCustomerDto;
import com.mes.cloud.api.dto.response.product.ProductDetailsDto;
import com.mes.cloud.api.dto.response.product.ProductDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xy
 * @version 2019-08-20 14:30:12
 * @email yuan.xue3@pactera.com
 */
@Api(tags = "产品", value = "产品接口")
@RestController
@RequestMapping(value = "/product")
public class ProductController  {

    private ProductService productService;

    @Autowired
    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    /**
     * 功能: 产品分页查询
     *
     * @param pageRequest
     * @return JsonResult<CommPager<ProductDto>>
     */
    @ApiOperation(value = "产品分页查询", notes = "产品分页查询")
    @PostMapping(value = "/pageList")
    public JsonResult<CommPager<ProductDto>> pageList(@Valid @RequestBody ProductPageRequest pageRequest) {
        return productService.pageList(pageRequest);
    }

    /**
     * 功能: 可售产品分页查询
     *
     * @param pageRequest
     * @return JsonResult<CommPager<ProductDto>>
     */
    @ApiOperation(value = "可售产品分页查询", notes = "可售产品分页查询")
    @PostMapping(value = "/productCustomerPageList")
    public JsonResult<CommPager<ProductCustomerDto>> productCustomerPageList(@Valid @RequestBody ProductCustomerPageRequest pageRequest) {
        return productService.productCustomerPageList(pageRequest);
    }

    /**
     * 功能: 产品查询所有
     *
     * @param baseProductRequest
     * @return JsonResult<List<ProductDto>>
     */
    @ApiOperation(value = "产品查询所有", notes = "产品查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<ProductDto>> list(@RequestBody ProductRequest baseProductRequest) {
        return productService.list(baseProductRequest);
    }

    /**
     * 功能: 产品新增
     *
     * @param baseProductRequest
     * @return JsonResult
     */
    @ApiOperation(value = "产品新增", notes = "产品新增")
    @PostMapping(value = "/add")
    public JsonResult add(@Valid @RequestBody ProductAddRequest baseProductRequest) {
        return productService.add(baseProductRequest);
    }

    /**
     * 功能: 产品修改
     *
     * @param baseProductRequest
     * @return JsonResult
     */
    @ApiOperation(value = "产品修改", notes = "产品修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody ProductUpdateRequest baseProductRequest) {
        return productService.update(baseProductRequest);

    }

    /**
     * 功能: 产品查看详情
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "产品查看详情", notes = "产品查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "产品主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<ProductDetailsDto> get(@PathVariable String id) {
        return productService.get(id);
    }

    /**
     * <产品禁用启用>
     *
     * @param productEnableRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author xy
     * @date 2019/8/21 14:51
     */
    @ApiOperation(value = "产品禁用启用", notes = "产品禁用启用")
    @PostMapping(value = "/updateEnableFlag")
    public JsonResult updateEnableFlag(@Valid @RequestBody ProductEnableRequest productEnableRequest) {
        return productService.updateEnableFlag(productEnableRequest);
    }

    /**
     * 功能: 产品分页查询
     *
     * @param pageRequest
     * @return JsonResult<CommPager<ProductDto>>
     */
    @ApiOperation(value = "产品按类型分页查询", notes = "产品按类型分页查询")
    @PostMapping(value = "/pageListByType")
    public JsonResult<CommPager<ProductDto>> pageListByType(@Valid @RequestBody ProductListPageRequest pageRequest) {
        return productService.pageListByType(pageRequest);
    }

    /**
     * 功能: 产品分页查询
     *
     * @param productListPageRequest
     * @return JsonResult<CommPager<ProductDto>>
     */
    @ApiOperation(value = "产品分页查询", notes = "产品分页查询")
    @PostMapping(value = "/pageListAndTypeFilter")
    public JsonResult<CommPager<ProductDto>> pageListAndTypeFilter(@Valid @RequestBody ProductListPageRequest productListPageRequest) {
        return productService.pageListAndTypeFilter(productListPageRequest);
    }
}
